﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ARA.WebApp
{
    public class PersonGridRow : Control
    {
        public Domain.Datas.Person Person { get; private set; }

        public PersonGridRow(Domain.Datas.Person person)
        {
            Person = person;
        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            base.RenderControl(writer);
            StringBuilder builder = new StringBuilder();
            for (int index = 0; index < Person.Segments.Count; index++)
            {
                if(index == 0)
                {
                    builder.AppendFormat("<tr><td rowspan='{0}'>{1}</td><td rowspan='{0}'>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr>",
                        Person.Segments.Count,
                        Person.Account,
                        Person.Name,
                        Person.Segments[index].LoginDate.ToString("yyyy-MM-dd hh:mm:ss"),
                        Person.Segments[index].LogoutDate.ToString("yyyy-MM-dd hh:mm:ss"),
                        Person.Segments[index].DurationText,
                        Person.Segments[index].Computer,
                        Person.Segments[index].IP);
                }
                else
                {
                    builder.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>",
                        Person.Segments[index].LoginDate.ToString("yyyy-MM-dd hh:mm:ss"),
                        Person.Segments[index].LogoutDate.ToString("yyyy-MM-dd hh:mm:ss"),
                        Person.Segments[index].DurationText,
                        Person.Segments[index].Computer,
                        Person.Segments[index].IP);
                }
            }
            writer.Write(builder.ToString());
        }
    }
}
